#include"Commd.hpp"
#include"Fifo.hpp"
#include<sys/ipc.h>
#include<sys/shm.h>

#include<iostream>
int main()
{
    //1. 生成钥匙
    key_t key = GetShmKeyOrDie();
    std::cout << "key: " << ToHex(key) << std::endl;

    //2. 获取共享内存
    int shmid = CreateShm(key,defaultsize);
    std::cout << "shmid: " << shmid << std::endl;
    //sleep(2);
    
    //3. 内存和进程挂接
    char* str = (char*)ShmAttach(shmid);
    std::cout << "Attach shm success, addr: " << ToHex((uint64_t)str) << std::endl;
   // sleep(2);
    Fifo fifo;
    syns syn;
    //以读方式打开管道
    syn.OpenReadOrDie();
    for(;;)
    {
        if(!syn.wait()) break;
        cout<<"shm content:"<< str << endl;
    }



    //4. 删除共享内存
    DeleteShm(shmid);
    std::cout << "DeleteShm : " << shmid << std::endl;
    //sleep(2);

    return 0;
}